{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "from matplotlib import lines\n",
    "from visualize import (\n",
    "    do_visualize,\n",
    "    visualize_diff,\n",
    "    visualize_ADF_result,\n",
    "    visualize_fast_result,\n",
    "    visualize_total_result,\n",
    ")\n",
    "from smooth_data import do_smooth\n",
    "from ADF_test import do_ADF_test\n",
    "from diff_test import do_diff_test\n",
    "from fast_test import do_fast_test\n",
    "import logging\n",
    "import numpy as np\n",
    "import math\n",
    "from typing import Dict, List\n",
    "\n",
    "matplotlib.use(\"Agg\")\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "from copy import deepcopy\n",
    "from typing import List\n",
    "\n",
    "def visualize_total_result(\n",
    "    data,\n",
    "    smooth_data,\n",
    "    diff_data,\n",
    "    turbulence_point_index,\n",
    "    upper_bound,\n",
    "    lower_bound,\n",
    "    stable_test_result,\n",
    "    fast_test_result,\n",
    "    FAST_STEP,\n",
    "    SLOW_STEP,\n",
    "    FAST_FREQ_RANGE,\n",
    "    SLOW_FREQ_RANGE,\n",
    "    TAN_RANGE,\n",
    "    DEBUG,\n",
    "    FIGSIZE,\n",
    "):\n",
    "    \"\"\"可视化所有结果\"\"\"\n",
    "    save_folder = r\".\\picture\"\n",
    "    # 分项文件夹\n",
    "    stable_data_folder = r\".\\total_test\"\n",
    "\n",
    "    os.makedirs(save_folder, exist_ok=True)\n",
    "    os.makedirs(os.path.join(save_folder, stable_data_folder), exist_ok=True)\n",
    "\n",
    "    turbulence_point = {}\n",
    "\n",
    "    for key in fast_test_result.keys():\n",
    "        plt.figure(figsize=FIGSIZE)\n",
    "        turbulence_point[key] = smooth_data[key].iloc[turbulence_point_index[key]]\n",
    "\n",
    "        # plt.plot(data[\"signal\"][key], label=\"Azimuth\")\n",
    "        # plt.plot(data[\"Freq\"][key], label=\"Freq\", color=\"grey\")\n",
    "        # plt.plot(data[\"Velo\"][key], label=\"Velo\")\n",
    "        # 画突变点\n",
    "        plt.scatter(\n",
    "            turbulence_point[key].index,\n",
    "            turbulence_point[key].values,\n",
    "            label=\"motor moving\",\n",
    "            color=\"red\",\n",
    "            marker=\"x\",\n",
    "        )\n",
    "        if DEBUG:  # debug就可视化上下限和差分\n",
    "            plt.plot(upper_bound[key], label=\"upper bound\")\n",
    "            plt.plot(lower_bound[key], label=\"lower bound\")\n",
    "            plt.plot(diff_data[key], label=\"diff data\")\n",
    "\n",
    "        for i in fast_test_result[key]:\n",
    "            if i[0]:  # 如果快速运动:\n",
    "                # stable_.append(data[\"Freq\"][key].iloc[i[1]:i[2]])\n",
    "                plt.plot(\n",
    "                    data[\"signal\"][i[1] : i[2]],\n",
    "                    color=\"green\",\n",
    "                    label=\"fast moving\",\n",
    "                )\n",
    "        # plt.plot(stable_, label = \"stable\", color = \"green\")\n",
    "        for i in stable_test_result[key]:\n",
    "            if i[0]:  # 如果是平稳态:\n",
    "                plt.plot(\n",
    "                    data[\"Freq\"][key].iloc[i[1] : i[2]], color=\"orange\", label=\"stable\"\n",
    "                )\n",
    "\n",
    "        handles, labels = plt.gca().get_legend_handles_labels()\n",
    "        by_label = dict(zip(labels, handles))\n",
    "        plt.legend(by_label.values(), by_label.keys())\n",
    "\n",
    "        if DEBUG:\n",
    "            os.makedirs(\n",
    "                os.path.join(save_folder, stable_data_folder + \"_debug\"), exist_ok=True\n",
    "            )\n",
    "            plt.savefig(\n",
    "                os.path.join(save_folder, stable_data_folder + \"_debug\", str(key))\n",
    "                + \".png\"\n",
    "            )\n",
    "        else:\n",
    "            os.makedirs(os.path.join(save_folder, stable_data_folder), exist_ok=True)\n",
    "            plt.savefig(\n",
    "                os.path.join(save_folder, stable_data_folder, str(key)) + \".png\"\n",
    "            )\n",
    "        plt.close(\"all\")\n",
    "    print(\"visualize ADF result done\".center(100, \"=\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "with open(r\"C:\\Users\\49498\\Desktop\\motion_rec\\data\\pattern.json\", \"r\") as f:\n",
    "    input_data = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "begin\n"
     ]
    }
   ],
   "source": [
    "\n",
    "config_data = input_data[\"config\"]\n",
    "signal_data = input_data[\"signal\"]\n",
    "\n",
    "SIGMA = config_data[\"SIGMA\"]  # 平滑系数\n",
    "ERROR_N = config_data[\"ERROR_N\"]  # 极差标准差系数\n",
    "FIGSIZE = config_data[\"FIGSIZE\"]  # 图片大小\n",
    "DEBUG = config_data[\"DEBUG\"]  # 是否调试\n",
    "\n",
    "SLOW_STEP = config_data[\"SLOW_STEP\"]  # 慢速步长\n",
    "FAST_STEP = config_data[\"FAST_STEP\"]  # 快速步长\n",
    "\n",
    "TAN_RANGE = config_data[\"TAN_RANGE\"]  # 斜率范围\n",
    "ST = config_data[\"ST\"]  # 静止阈值\n",
    "FAST_FREQ_RANGE, SLOW_FREQ_RANGE = (\n",
    "    config_data[\"FAST_FREQ_RANGE\"],\n",
    "    config_data[\"SLOW_FREQ_RANGE\"],\n",
    ")\n",
    "\n",
    "print(\"begin\")\n",
    "output_data_folder = \"data\\out_put\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'signal': [-40.641,\n",
       "  -39.159,\n",
       "  -43.062,\n",
       "  -39.752,\n",
       "  -40.106,\n",
       "  -41.545,\n",
       "  -40.484,\n",
       "  -39.518,\n",
       "  -36.097,\n",
       "  -36.715,\n",
       "  -40.648,\n",
       "  -36.073,\n",
       "  -38.196,\n",
       "  -38.796,\n",
       "  -37.832,\n",
       "  -38.56,\n",
       "  -38.293,\n",
       "  -36.488,\n",
       "  -36.38,\n",
       "  -36.185,\n",
       "  -36.744,\n",
       "  -38.433,\n",
       "  -36.321,\n",
       "  -35.218,\n",
       "  -36.175,\n",
       "  -35.438,\n",
       "  -35.558,\n",
       "  -36.4,\n",
       "  -35.612,\n",
       "  -36.508,\n",
       "  -34.641,\n",
       "  -36.49,\n",
       "  -36.221,\n",
       "  -35.775,\n",
       "  -37.722,\n",
       "  -33.154,\n",
       "  -34.074,\n",
       "  -34.968,\n",
       "  -32.653,\n",
       "  -35.549,\n",
       "  -33.75,\n",
       "  -33.704,\n",
       "  -32.952,\n",
       "  -32.771,\n",
       "  -33.76,\n",
       "  -32.74,\n",
       "  -32.686,\n",
       "  -31.707,\n",
       "  -31.053,\n",
       "  -30.848,\n",
       "  -32.634,\n",
       "  -31.506,\n",
       "  -32.61,\n",
       "  -32.322,\n",
       "  -31.028,\n",
       "  -29.302,\n",
       "  -31.416,\n",
       "  -30.087,\n",
       "  -30.496,\n",
       "  -28.965,\n",
       "  -30.986,\n",
       "  -29.678,\n",
       "  -28.971,\n",
       "  -28.234,\n",
       "  -27.606,\n",
       "  -28.875,\n",
       "  -30.269,\n",
       "  -29.331,\n",
       "  -29.465,\n",
       "  -25.863,\n",
       "  -28.647,\n",
       "  -27.093,\n",
       "  -27.851,\n",
       "  -26.584,\n",
       "  -28.051,\n",
       "  -28.502,\n",
       "  -28.339,\n",
       "  -26.24,\n",
       "  -26.722,\n",
       "  -26.554,\n",
       "  -24.753,\n",
       "  -25.696,\n",
       "  -25.606,\n",
       "  -24.029,\n",
       "  -26.239,\n",
       "  -24.55,\n",
       "  -24.229,\n",
       "  -25.122,\n",
       "  -24.478,\n",
       "  -25.674,\n",
       "  -25.474,\n",
       "  -24.037,\n",
       "  -23.235,\n",
       "  -21.186,\n",
       "  -24.254,\n",
       "  -23.219,\n",
       "  -23.305,\n",
       "  -24.972,\n",
       "  -23.294,\n",
       "  -24.467,\n",
       "  -21.648,\n",
       "  -23.197,\n",
       "  -22.024,\n",
       "  -22.488,\n",
       "  -21.454,\n",
       "  -22.178,\n",
       "  -20.905,\n",
       "  -20.475,\n",
       "  -19.319,\n",
       "  -21.047,\n",
       "  -22.808,\n",
       "  -21.328,\n",
       "  -18.953,\n",
       "  -21.198,\n",
       "  -18.985,\n",
       "  -19.644,\n",
       "  -18.148,\n",
       "  -21.368,\n",
       "  -19.423,\n",
       "  -20.256,\n",
       "  -15.959,\n",
       "  -17.863,\n",
       "  -17.126,\n",
       "  -19.389,\n",
       "  -18.618,\n",
       "  -18.245,\n",
       "  -16.692,\n",
       "  -17.891,\n",
       "  -16.733,\n",
       "  -19.311,\n",
       "  -17.435,\n",
       "  -17.729,\n",
       "  -18.303,\n",
       "  -16.04,\n",
       "  -16.088,\n",
       "  -16.163,\n",
       "  -17.35,\n",
       "  -14.716,\n",
       "  -15.316,\n",
       "  -15.788,\n",
       "  -15.291,\n",
       "  -15.401,\n",
       "  -16.713,\n",
       "  -15.075,\n",
       "  -15.447,\n",
       "  -15.42,\n",
       "  -15.42,\n",
       "  -14.627,\n",
       "  -15.919,\n",
       "  -12.781,\n",
       "  -13.049,\n",
       "  -13.419,\n",
       "  -13.26,\n",
       "  -13.852,\n",
       "  -11.862,\n",
       "  -12.842,\n",
       "  -13.248,\n",
       "  -11.014,\n",
       "  -12.415,\n",
       "  -12.612,\n",
       "  -12.145,\n",
       "  -12.529,\n",
       "  -12.628,\n",
       "  -8.816,\n",
       "  -9.5149,\n",
       "  -10.694,\n",
       "  -12.087,\n",
       "  -11.528,\n",
       "  -10.669,\n",
       "  -9.5341,\n",
       "  -11.49,\n",
       "  -12.318,\n",
       "  -11.268,\n",
       "  -9.3185,\n",
       "  -9.0953,\n",
       "  -8.8697,\n",
       "  -9.2815,\n",
       "  -8.8047,\n",
       "  -9.2942,\n",
       "  -7.7929,\n",
       "  -9.8508,\n",
       "  -7.8722,\n",
       "  -9.0097,\n",
       "  -8.3307,\n",
       "  -7.2766,\n",
       "  -6.6281,\n",
       "  -8.6209,\n",
       "  -6.0803,\n",
       "  -6.5149,\n",
       "  -7.0832,\n",
       "  -7.0479,\n",
       "  -6.9103,\n",
       "  -6.8327,\n",
       "  -6.3463,\n",
       "  -6.1532,\n",
       "  -5.221,\n",
       "  -4.3565,\n",
       "  -5.2587,\n",
       "  -5.7746,\n",
       "  -4.7816,\n",
       "  -5.0625,\n",
       "  -6.119,\n",
       "  -3.9787,\n",
       "  -4.4668,\n",
       "  -4.4772,\n",
       "  -3.9429,\n",
       "  -4.0366,\n",
       "  -5.085,\n",
       "  -4.1484,\n",
       "  -3.9758,\n",
       "  -4.2041,\n",
       "  -1.838,\n",
       "  -4.2396,\n",
       "  -3.6953,\n",
       "  -3.7682,\n",
       "  -4.0751,\n",
       "  -2.9392,\n",
       "  -2.8684,\n",
       "  -0.91294,\n",
       "  -2.5407,\n",
       "  -3.2,\n",
       "  -0.38375,\n",
       "  -1.3826,\n",
       "  -6.8588,\n",
       "  -13.821,\n",
       "  -19.889,\n",
       "  -27.87,\n",
       "  -36.498,\n",
       "  -46.508,\n",
       "  -55.288,\n",
       "  -58.946,\n",
       "  -63.209,\n",
       "  -65.583,\n",
       "  -68.12,\n",
       "  -70.7,\n",
       "  -73.413,\n",
       "  -76.068,\n",
       "  -82.2,\n",
       "  -82.826,\n",
       "  -84.444,\n",
       "  -90.194,\n",
       "  -91.775,\n",
       "  -189.47,\n",
       "  -220.57,\n",
       "  -218.6,\n",
       "  -222.39,\n",
       "  -222.96,\n",
       "  -223.35,\n",
       "  -226.94,\n",
       "  -229.09,\n",
       "  -231.98,\n",
       "  -233.41,\n",
       "  -235.29,\n",
       "  -237.26,\n",
       "  -240.23,\n",
       "  -242.29,\n",
       "  -242.23,\n",
       "  -248.74,\n",
       "  -246.49,\n",
       "  -250.63,\n",
       "  -252.24,\n",
       "  -257.19,\n",
       "  -258.41,\n",
       "  -260.42,\n",
       "  -262.05,\n",
       "  -266.49,\n",
       "  -266.71,\n",
       "  -270.78,\n",
       "  -271.89,\n",
       "  -273.72,\n",
       "  -276.47,\n",
       "  -278.16,\n",
       "  -280.7,\n",
       "  -284.84,\n",
       "  -286.42,\n",
       "  -290.13,\n",
       "  -298.6,\n",
       "  -208.87,\n",
       "  -125.66,\n",
       "  -127.69,\n",
       "  -128.74,\n",
       "  -131.11,\n",
       "  -133.45,\n",
       "  -134.68,\n",
       "  -137.17,\n",
       "  -140.08,\n",
       "  -143.26,\n",
       "  -145.52,\n",
       "  22.265,\n",
       "  209.6,\n",
       "  217.38,\n",
       "  220.63,\n",
       "  228.66,\n",
       "  233.48,\n",
       "  237.49,\n",
       "  242.19,\n",
       "  244.43,\n",
       "  252.05,\n",
       "  253.72,\n",
       "  257.92,\n",
       "  264.53,\n",
       "  267.59,\n",
       "  272.92,\n",
       "  277.03,\n",
       "  280.93,\n",
       "  282.97,\n",
       "  287.56,\n",
       "  290.54,\n",
       "  294.44,\n",
       "  297.2,\n",
       "  268.55,\n",
       "  -176.42,\n",
       "  -200.23,\n",
       "  -224.57,\n",
       "  -255.12,\n",
       "  -283.06,\n",
       "  -617.9,\n",
       "  -600.41,\n",
       "  -581.68,\n",
       "  -562.75,\n",
       "  -544.83,\n",
       "  -523.57,\n",
       "  -501.35,\n",
       "  -479.32,\n",
       "  -455.48,\n",
       "  -431.39,\n",
       "  -408.02,\n",
       "  -381.94,\n",
       "  -357.97,\n",
       "  -328.22,\n",
       "  -303.03,\n",
       "  -301.5,\n",
       "  -167.49,\n",
       "  -164.92,\n",
       "  -164.64,\n",
       "  -166.32,\n",
       "  -164.71,\n",
       "  -166.88,\n",
       "  -171.65,\n",
       "  -169.84,\n",
       "  -172.81,\n",
       "  -81.364,\n",
       "  131.24,\n",
       "  166.77,\n",
       "  164.9,\n",
       "  165.91,\n",
       "  163.0,\n",
       "  162.97,\n",
       "  162.45,\n",
       "  161.03,\n",
       "  160.98,\n",
       "  159.57,\n",
       "  157.61,\n",
       "  155.74,\n",
       "  158.55,\n",
       "  155.24,\n",
       "  155.09,\n",
       "  154.7,\n",
       "  153.39,\n",
       "  151.52,\n",
       "  151.1,\n",
       "  150.59,\n",
       "  151.33,\n",
       "  148.14,\n",
       "  148.92,\n",
       "  147.59,\n",
       "  146.18,\n",
       "  144.5,\n",
       "  15.189,\n",
       "  -117.44,\n",
       "  -119.92,\n",
       "  -119.35,\n",
       "  -121.45,\n",
       "  -121.81,\n",
       "  -122.47,\n",
       "  -124.8,\n",
       "  -125.27,\n",
       "  -125.72,\n",
       "  -128.99,\n",
       "  -127.21,\n",
       "  -126.9,\n",
       "  -129.45,\n",
       "  -246.54,\n",
       "  -270.03,\n",
       "  -242.44,\n",
       "  -240.86,\n",
       "  -243.14,\n",
       "  -244.63,\n",
       "  -247.62,\n",
       "  -247.76,\n",
       "  -249.97,\n",
       "  -251.05,\n",
       "  -252.64,\n",
       "  -254.42,\n",
       "  -255.63,\n",
       "  -256.26,\n",
       "  -259.08,\n",
       "  -258.09,\n",
       "  -260.14,\n",
       "  -260.64,\n",
       "  -262.39,\n",
       "  -263.49,\n",
       "  -266.78,\n",
       "  -267.63,\n",
       "  -268.38,\n",
       "  -269.14,\n",
       "  -269.43,\n",
       "  -272.16,\n",
       "  -271.92,\n",
       "  -274.01,\n",
       "  -274.62,\n",
       "  -313.9,\n",
       "  -242.9,\n",
       "  -219.37,\n",
       "  -218.87,\n",
       "  -219.35,\n",
       "  -221.6,\n",
       "  -222.99,\n",
       "  -223.89,\n",
       "  -225.81,\n",
       "  -226.34,\n",
       "  -205.26,\n",
       "  31.717,\n",
       "  158.16,\n",
       "  158.0,\n",
       "  156.66,\n",
       "  157.53,\n",
       "  155.19,\n",
       "  155.84,\n",
       "  152.48,\n",
       "  152.89,\n",
       "  151.26,\n",
       "  151.28,\n",
       "  150.43,\n",
       "  146.81,\n",
       "  146.83,\n",
       "  145.86,\n",
       "  146.86,\n",
       "  147.09,\n",
       "  144.45,\n",
       "  144.73,\n",
       "  143.62,\n",
       "  141.17,\n",
       "  141.78,\n",
       "  139.78,\n",
       "  141.19,\n",
       "  -33.34,\n",
       "  -187.74,\n",
       "  -190.91,\n",
       "  -191.01,\n",
       "  -192.77,\n",
       "  -195.84,\n",
       "  -195.91,\n",
       "  -195.42,\n",
       "  -197.2,\n",
       "  -199.37,\n",
       "  -199.98,\n",
       "  -232.36,\n",
       "  -305.03,\n",
       "  -250.87,\n",
       "  -253.8,\n",
       "  -252.67,\n",
       "  -256.88,\n",
       "  -256.92,\n",
       "  -259.95,\n",
       "  -260.47,\n",
       "  -261.65,\n",
       "  -261.96,\n",
       "  -262.74,\n",
       "  -264.68,\n",
       "  -266.67,\n",
       "  -266.78,\n",
       "  -268.1,\n",
       "  -270.08,\n",
       "  -270.94,\n",
       "  -272.4,\n",
       "  -275.1,\n",
       "  -274.65,\n",
       "  -277.36,\n",
       "  -278.61,\n",
       "  -279.12,\n",
       "  -327.88,\n",
       "  -268.9,\n",
       "  -269.32,\n",
       "  -270.01,\n",
       "  -272.4,\n",
       "  -273.01,\n",
       "  -274.72,\n",
       "  -275.38,\n",
       "  -276.31,\n",
       "  -73.802,\n",
       "  136.47,\n",
       "  135.96,\n",
       "  134.62,\n",
       "  135.42,\n",
       "  132.25,\n",
       "  131.29,\n",
       "  129.44,\n",
       "  131.26,\n",
       "  130.38,\n",
       "  128.6,\n",
       "  128.74,\n",
       "  127.18,\n",
       "  126.45,\n",
       "  125.43,\n",
       "  124.92,\n",
       "  123.74,\n",
       "  125.59,\n",
       "  120.79,\n",
       "  119.26,\n",
       "  -85.226,\n",
       "  -233.75,\n",
       "  -234.19,\n",
       "  -235.03,\n",
       "  -236.18,\n",
       "  -236.52,\n",
       "  -237.76,\n",
       "  -238.5,\n",
       "  -238.57,\n",
       "  -240.22,\n",
       "  -243.82,\n",
       "  -245.95],\n",
       " 'config': {'SIGMA': 1,\n",
       "  'ERROR_N': 2.5,\n",
       "  'FIGSIZE': [25, 12],\n",
       "  'DEBUG': False,\n",
       "  'SLOW_STEP': 50,\n",
       "  'FAST_STEP': 25,\n",
       "  'TAN_RANGE': [10, 90],\n",
       "  'ST': 8,\n",
       "  'FAST_FREQ_RANGE': 90,\n",
       "  'SLOW_FREQ_RANGE': 20}}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-4.06,\n",
       " -3.92,\n",
       " -4.31,\n",
       " -3.98,\n",
       " -4.01,\n",
       " -4.15,\n",
       " -4.05,\n",
       " -3.95,\n",
       " -3.61,\n",
       " -3.67,\n",
       " -4.06,\n",
       " -3.61,\n",
       " -3.82,\n",
       " -3.88,\n",
       " -3.78,\n",
       " -3.86,\n",
       " -3.83,\n",
       " -3.65,\n",
       " -3.64,\n",
       " -3.62,\n",
       " -3.67,\n",
       " -3.84,\n",
       " -3.63,\n",
       " -3.52,\n",
       " -3.62,\n",
       " -3.54,\n",
       " -3.56,\n",
       " -3.64,\n",
       " -3.56,\n",
       " -3.65,\n",
       " -3.46,\n",
       " -3.65,\n",
       " -3.62,\n",
       " -3.58,\n",
       " -3.77,\n",
       " -3.32,\n",
       " -3.41,\n",
       " -3.5,\n",
       " -3.27,\n",
       " -3.55,\n",
       " -3.38,\n",
       " -3.37,\n",
       " -3.3,\n",
       " -3.28,\n",
       " -3.38,\n",
       " -3.27,\n",
       " -3.27,\n",
       " -3.17,\n",
       " -3.11,\n",
       " -3.08,\n",
       " -3.26,\n",
       " -3.15,\n",
       " -3.26,\n",
       " -3.23,\n",
       " -3.1,\n",
       " -2.93,\n",
       " -3.14,\n",
       " -3.01,\n",
       " -3.05,\n",
       " -2.9,\n",
       " -3.1,\n",
       " -2.97,\n",
       " -2.9,\n",
       " -2.82,\n",
       " -2.76,\n",
       " -2.89,\n",
       " -3.03,\n",
       " -2.93,\n",
       " -2.95,\n",
       " -2.59,\n",
       " -2.86,\n",
       " -2.71,\n",
       " -2.79,\n",
       " -2.66,\n",
       " -2.81,\n",
       " -2.85,\n",
       " -2.83,\n",
       " -2.62,\n",
       " -2.67,\n",
       " -2.66,\n",
       " -2.48,\n",
       " -2.57,\n",
       " -2.56,\n",
       " -2.4,\n",
       " -2.62,\n",
       " -2.46,\n",
       " -2.42,\n",
       " -2.51,\n",
       " -2.45,\n",
       " -2.57,\n",
       " -2.55,\n",
       " -2.4,\n",
       " -2.32,\n",
       " -2.12,\n",
       " -2.43,\n",
       " -2.32,\n",
       " -2.33,\n",
       " -2.5,\n",
       " -2.33,\n",
       " -2.45,\n",
       " -2.16,\n",
       " -2.32,\n",
       " -2.2,\n",
       " -2.25,\n",
       " -2.15,\n",
       " -2.22,\n",
       " -2.09,\n",
       " -2.05,\n",
       " -1.93,\n",
       " -2.1,\n",
       " -2.28,\n",
       " -2.13,\n",
       " -1.9,\n",
       " -2.12,\n",
       " -1.9,\n",
       " -1.96,\n",
       " -1.81,\n",
       " -2.14,\n",
       " -1.94,\n",
       " -2.03,\n",
       " -1.6,\n",
       " -1.79,\n",
       " -1.71,\n",
       " -1.94,\n",
       " -1.86,\n",
       " -1.82,\n",
       " -1.67,\n",
       " -1.79,\n",
       " -1.67,\n",
       " -1.93,\n",
       " -1.74,\n",
       " -1.77,\n",
       " -1.83,\n",
       " -1.6,\n",
       " -1.61,\n",
       " -1.62,\n",
       " -1.74,\n",
       " -1.47,\n",
       " -1.53,\n",
       " -1.58,\n",
       " -1.53,\n",
       " -1.54,\n",
       " -1.67,\n",
       " -1.51,\n",
       " -1.54,\n",
       " -1.54,\n",
       " -1.54,\n",
       " -1.46,\n",
       " -1.59,\n",
       " -1.28,\n",
       " -1.3,\n",
       " -1.34,\n",
       " -1.33,\n",
       " -1.39,\n",
       " -1.19,\n",
       " -1.28,\n",
       " -1.32,\n",
       " -1.1,\n",
       " -1.24,\n",
       " -1.26,\n",
       " -1.21,\n",
       " -1.25,\n",
       " -1.26,\n",
       " -8.82,\n",
       " -9.51,\n",
       " -1.07,\n",
       " -1.21,\n",
       " -1.15,\n",
       " -1.07,\n",
       " -9.53,\n",
       " -1.15,\n",
       " -1.23,\n",
       " -1.13,\n",
       " -9.32,\n",
       " -9.1,\n",
       " -8.87,\n",
       " -9.28,\n",
       " -8.8,\n",
       " -9.29,\n",
       " -7.79,\n",
       " -9.85,\n",
       " -7.87,\n",
       " -9.01,\n",
       " -8.33,\n",
       " -7.28,\n",
       " -6.63,\n",
       " -8.62,\n",
       " -6.08,\n",
       " -6.51,\n",
       " -7.08,\n",
       " -7.05,\n",
       " -6.91,\n",
       " -6.83,\n",
       " -6.35,\n",
       " -6.15,\n",
       " -5.22,\n",
       " -4.36,\n",
       " -5.26,\n",
       " -5.77,\n",
       " -4.78,\n",
       " -5.06,\n",
       " -6.12,\n",
       " -3.98,\n",
       " -4.47,\n",
       " -4.48,\n",
       " -3.94,\n",
       " -4.04,\n",
       " -5.08,\n",
       " -4.15,\n",
       " -3.98,\n",
       " -4.2,\n",
       " -1.84,\n",
       " -4.24,\n",
       " -3.7,\n",
       " -3.77,\n",
       " -4.08,\n",
       " -2.94,\n",
       " -2.87,\n",
       " -9.13,\n",
       " -2.54,\n",
       " -3.2,\n",
       " -3.84,\n",
       " -1.38,\n",
       " -6.86,\n",
       " -1.38,\n",
       " -1.99,\n",
       " -2.79,\n",
       " -3.65,\n",
       " -4.65,\n",
       " -5.53,\n",
       " -5.89,\n",
       " -6.32,\n",
       " -6.56,\n",
       " -6.81,\n",
       " -7.07,\n",
       " -7.34,\n",
       " -7.61,\n",
       " -8.22,\n",
       " -8.28,\n",
       " -8.44,\n",
       " -9.02,\n",
       " -9.18,\n",
       " -1.89,\n",
       " -2.21,\n",
       " -2.19,\n",
       " -2.22,\n",
       " -2.23,\n",
       " -2.23,\n",
       " -2.27,\n",
       " -2.29,\n",
       " -2.32,\n",
       " -2.33,\n",
       " -2.35,\n",
       " -2.37,\n",
       " -2.4,\n",
       " -2.42,\n",
       " -2.42,\n",
       " -2.49,\n",
       " -2.46,\n",
       " -2.51,\n",
       " -2.52,\n",
       " -2.57,\n",
       " -2.58,\n",
       " -2.6,\n",
       " -2.62,\n",
       " -2.66,\n",
       " -2.67,\n",
       " -2.71,\n",
       " -2.72,\n",
       " -2.74,\n",
       " -2.76,\n",
       " -2.78,\n",
       " -2.81,\n",
       " -2.85,\n",
       " -2.86,\n",
       " -2.9,\n",
       " -2.99,\n",
       " -2.09,\n",
       " -1.26,\n",
       " -1.28,\n",
       " -1.29,\n",
       " -1.31,\n",
       " -1.33,\n",
       " -1.35,\n",
       " -1.37,\n",
       " -1.4,\n",
       " -1.43,\n",
       " -1.46,\n",
       " 2.23,\n",
       " 2.1,\n",
       " 2.17,\n",
       " 2.21,\n",
       " 2.29,\n",
       " 2.33,\n",
       " 2.37,\n",
       " 2.42,\n",
       " 2.44,\n",
       " 2.52,\n",
       " 2.54,\n",
       " 2.58,\n",
       " 2.65,\n",
       " 2.68,\n",
       " 2.73,\n",
       " 2.77,\n",
       " 2.81,\n",
       " 2.83,\n",
       " 2.88,\n",
       " 2.91,\n",
       " 2.94,\n",
       " 2.97,\n",
       " 2.69,\n",
       " -1.76,\n",
       " -2.0,\n",
       " -2.25,\n",
       " -2.55,\n",
       " -2.83,\n",
       " -6.18,\n",
       " -6.0,\n",
       " -5.82,\n",
       " -5.63,\n",
       " -5.45,\n",
       " -5.24,\n",
       " -5.01,\n",
       " -4.79,\n",
       " -4.55,\n",
       " -4.31,\n",
       " -4.08,\n",
       " -3.82,\n",
       " -3.58,\n",
       " -3.28,\n",
       " -3.03,\n",
       " -3.02,\n",
       " -1.67,\n",
       " -1.65,\n",
       " -1.65,\n",
       " -1.66,\n",
       " -1.65,\n",
       " -1.67,\n",
       " -1.72,\n",
       " -1.7,\n",
       " -1.73,\n",
       " -8.14,\n",
       " 1.31,\n",
       " 1.67,\n",
       " 1.65,\n",
       " 1.66,\n",
       " 1.63,\n",
       " 1.63,\n",
       " 1.62,\n",
       " 1.61,\n",
       " 1.61,\n",
       " 1.6,\n",
       " 1.58,\n",
       " 1.56,\n",
       " 1.59,\n",
       " 1.55,\n",
       " 1.55,\n",
       " 1.55,\n",
       " 1.53,\n",
       " 1.52,\n",
       " 1.51,\n",
       " 1.51,\n",
       " 1.51,\n",
       " 1.48,\n",
       " 1.49,\n",
       " 1.48,\n",
       " 1.46,\n",
       " 1.45,\n",
       " 1.52,\n",
       " -1.17,\n",
       " -1.2,\n",
       " -1.19,\n",
       " -1.21,\n",
       " -1.22,\n",
       " -1.22,\n",
       " -1.25,\n",
       " -1.25,\n",
       " -1.26,\n",
       " -1.29,\n",
       " -1.27,\n",
       " -1.27,\n",
       " -1.29,\n",
       " -2.47,\n",
       " -2.7,\n",
       " -2.42,\n",
       " -2.41,\n",
       " -2.43,\n",
       " -2.45,\n",
       " -2.48,\n",
       " -2.48,\n",
       " -2.5,\n",
       " -2.51,\n",
       " -2.53,\n",
       " -2.54,\n",
       " -2.56,\n",
       " -2.56,\n",
       " -2.59,\n",
       " -2.58,\n",
       " -2.6,\n",
       " -2.61,\n",
       " -2.62,\n",
       " -2.63,\n",
       " -2.67,\n",
       " -2.68,\n",
       " -2.68,\n",
       " -2.69,\n",
       " -2.69,\n",
       " -2.72,\n",
       " -2.72,\n",
       " -2.74,\n",
       " -2.75,\n",
       " -3.14,\n",
       " -2.43,\n",
       " -2.19,\n",
       " -2.19,\n",
       " -2.19,\n",
       " -2.22,\n",
       " -2.23,\n",
       " -2.24,\n",
       " -2.26,\n",
       " -2.26,\n",
       " -2.05,\n",
       " 3.17,\n",
       " 1.58,\n",
       " 1.58,\n",
       " 1.57,\n",
       " 1.58,\n",
       " 1.55,\n",
       " 1.56,\n",
       " 1.52,\n",
       " 1.53,\n",
       " 1.51,\n",
       " 1.51,\n",
       " 1.5,\n",
       " 1.47,\n",
       " 1.47,\n",
       " 1.46,\n",
       " 1.47,\n",
       " 1.47,\n",
       " 1.44,\n",
       " 1.45,\n",
       " 1.44,\n",
       " 1.41,\n",
       " 1.42,\n",
       " 1.4,\n",
       " 1.41,\n",
       " -3.33,\n",
       " -1.88,\n",
       " -1.91,\n",
       " -1.91,\n",
       " -1.93,\n",
       " -1.96,\n",
       " -1.96,\n",
       " -1.95,\n",
       " -1.97,\n",
       " -1.99,\n",
       " -2.0,\n",
       " -2.32,\n",
       " -3.05,\n",
       " -2.51,\n",
       " -2.54,\n",
       " -2.53,\n",
       " -2.57,\n",
       " -2.57,\n",
       " -2.6,\n",
       " -2.6,\n",
       " -2.62,\n",
       " -2.62,\n",
       " -2.63,\n",
       " -2.65,\n",
       " -2.67,\n",
       " -2.67,\n",
       " -2.68,\n",
       " -2.7,\n",
       " -2.71,\n",
       " -2.72,\n",
       " -2.75,\n",
       " -2.75,\n",
       " -2.77,\n",
       " -2.79,\n",
       " -2.79,\n",
       " -3.28,\n",
       " -2.69,\n",
       " -2.69,\n",
       " -2.7,\n",
       " -2.72,\n",
       " -2.73,\n",
       " -2.75,\n",
       " -2.75,\n",
       " -2.76,\n",
       " -7.38,\n",
       " 1.36,\n",
       " 1.36,\n",
       " 1.35,\n",
       " 1.35,\n",
       " 1.32,\n",
       " 1.31,\n",
       " 1.29,\n",
       " 1.31,\n",
       " 1.3,\n",
       " 1.29,\n",
       " 1.29,\n",
       " 1.27,\n",
       " 1.26,\n",
       " 1.25,\n",
       " 1.25,\n",
       " 1.24,\n",
       " 1.26,\n",
       " 1.21,\n",
       " 1.19,\n",
       " -8.52,\n",
       " -2.34,\n",
       " -2.34,\n",
       " -2.35,\n",
       " -2.36,\n",
       " -2.37,\n",
       " -2.38,\n",
       " -2.38,\n",
       " -2.39,\n",
       " -2.4,\n",
       " -2.44,\n",
       " -2.46]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 定义一个函数，接受两个列表作为参数，返回将第二个列表转换为和第一个列表相同数量级的新列表\n",
    "def convert_scale(aim_list, scale1=None, list1=None):\n",
    "    # 计算第一个列表中的第一个元素的数量级\n",
    "    \n",
    "    if list1 is not None:\n",
    "        avg = np.mean(list1)\n",
    "        scale1 = math.floor(math.log10(avg))\n",
    "    # 创建一个空列表，用来存放转换后的结果\n",
    "    elif scale1:\n",
    "        magic = 10 ** (scale1-1)\n",
    "        scale1 = math.floor(math.log10(magic))\n",
    "    else:\n",
    "        raise ValueError(\"scale1 and list1 cannot be None at the same time\")\n",
    "    \n",
    "    new_aim_list = []\n",
    "    # 遍历第二个列表中的每个元素\n",
    "    for num in aim_list:\n",
    "        # 计算该元素的数量级\n",
    "        scale2 = math.floor(math.log10(abs(num)))\n",
    "        # 计算数量级的差值\n",
    "        diff = scale2 - scale1\n",
    "        # 用10的幂来进行转换，保留两位小数\n",
    "        new_num = round(num / (10**diff), 2)\n",
    "        # 将转换后的元素添加到新列表中\n",
    "        new_aim_list.append(new_num)\n",
    "    # 返回新列表\n",
    "    return new_aim_list\n",
    "\n",
    "# data: dict = get_data(output_data_folder)\n",
    "x = convert_scale(signal_data, scale1=1)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 平滑Freq曲线\n",
    "smooth_data = do_smooth(signal_data, sigma=SIGMA)\n",
    "\n",
    "# 可视化数据\n",
    "# do_visualize(data, smooth_data, FIGSIZE) # 全部数据\n",
    "# visualize_smooth(data, smooth_data,FIGSIZE) # 平滑数据\n",
    "\n",
    "## 机动检测: \n",
    "diff_data, turbulence_point_index, upper_bound, lower_bound = do_diff_test(\n",
    "    smooth_data, ERROR_N\n",
    ")\n",
    "\n",
    "# stable test\n",
    "stable_test_result, stable_data = do_ADF_test(\n",
    "    smooth_data, SLOW_STEP, SLOW_FREQ_RANGE, ST\n",
    ")\n",
    "\n",
    "# fast test\n",
    "fast_test_result, fast_data = do_fast_test(\n",
    "    smooth_data, FAST_STEP, TAN_RANGE[1], TAN_RANGE[0], FAST_FREQ_RANGE\n",
    ")\n",
    "\n",
    "if DEBUG:  # d单独可视化\n",
    "    visualize_fast_result(\n",
    "        fast_test_result,\n",
    "        input_data,\n",
    "        FAST_STEP,\n",
    "        FAST_FREQ_RANGE,\n",
    "        DEBUG,\n",
    "        FIGSIZE=FIGSIZE,\n",
    "    )\n",
    "    visualize_diff(\n",
    "        input_data,\n",
    "        smooth_data,\n",
    "        turbulence_point_index,\n",
    "        diff_data,\n",
    "        ERROR_N,\n",
    "        upper_bound,\n",
    "        lower_bound,\n",
    "        DEBUG,\n",
    "        FIGSIZE,\n",
    "    )\n",
    "    visualize_ADF_result(\n",
    "        stable_test_result, input_data, SLOW_STEP, SLOW_FREQ_RANGE, DEBUG, FIGSIZE\n",
    "    )\n",
    "\n",
    "# 可视化结果\n",
    "\n",
    "visualize_total_result(\n",
    "    input_data,\n",
    "    smooth_data,\n",
    "    diff_data,\n",
    "    turbulence_point_index,\n",
    "    upper_bound,\n",
    "    lower_bound,\n",
    "    stable_test_result,\n",
    "    fast_test_result,\n",
    "    FAST_STEP,\n",
    "    SLOW_STEP,\n",
    "    FAST_FREQ_RANGE,\n",
    "    SLOW_FREQ_RANGE,\n",
    "    TAN_RANGE,\n",
    "    DEBUG,\n",
    "    FIGSIZE,\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import math \n",
    "x = [1,2,3,4,4,5,5,5,5,6]\n",
    "x = pd.Series(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-3.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.log10(abs(0.001))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "auto-sign",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
